<template>
    <div>
        <van-nav-bar title="会员注册" left-text="返回" left-arrow @click-left="()=>{$router.push('/login')}" />

        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <van-field v-model="username" name="username" label="账号" placeholder="请输入账号(必填)"
                    :rules="[{ required: true, message: '请输入账号' }]" />

                <van-field v-model="password" type="password" name="password" label="密码" placeholder="请输入密码(必填)"
                    :rules="[{ required: true, message: '请输入密码' }]" />
                <van-field v-model="xpassword" type="password" name="xpassword" label="密码" placeholder="请输入确定密码(必填)"
                    :rules="[{ required: true, message: '请输入确定密码' }]" />
                <van-field v-model="xmword" name="xmword" label="姓名" placeholder="请输入姓名(必填)"
                    :rules="[{ required: true, message: '请输入姓名' }]" />
                <van-field v-model="yxword" name="yxword" label="邮箱" placeholder="请输入邮箱" /> <van-field v-model="sjword"
                    name="sjword" label="手机" placeholder="请输入手机(必填)" is-link  :rules="[{ required: true, message: '请输入手机' }]" />
                <van-field v-model="lyword" name="lyword" label="留言" placeholder="请输入留言" />
            </van-cell-group>

            <div style="margin: 16px;">
                <van-button  block type="primary" native-type="submit" style="background-color: crimson;border: none;">
            注册
                </van-button>
            </div>
        </van-form>

    </div>
</template>

<script setup>
import { ref } from 'vue';
const username = ref('');
const password = ref('');
const xpassword = ref('');
const xmword = ref('');
const yxword = ref('');
const lyword = ref('');
import { registerApi } from '@/api/api';
import { useRouter } from 'vue-router';
import { showSuccessToast, showFailToast } from 'vant';
const router = useRouter()
const onSubmit = (values) => {
    console.log('submit', values);
    registerApi(username.value, password.value).then(res => {
        console.log(res);
        if (res.data.code == 0) {
            showSuccessToast('注册成功');
            router.push('/login')
        } else {
            showFailToast('注册失败');
        }
    })
};

</script>

<style lang="scss" scoped></style>